package com.leaves.leetcode.array.t643_FindMaxAverage;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.leaves.leetcode.UnitTesting;

import java.util.List;

public class T643Main extends UnitTesting<Object[], Double> {

    Solution solution = new Solution();

    @Override
    protected void generateTestData() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            testDataList.add(createTestData(
                    objectMapper.readValue("[[1,12,-5,-6,50,3], 4]", new TypeReference<Object[]>() {}),
                    12.75
            ));
            testDataList.add(createTestData(
                    objectMapper.readValue("[[5], 1]", new TypeReference<Object[]>() {}),
                    5.00000
            ));
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }


    @Override
    public Double run(Object[] inputData) {
        List<Integer> list = (List) inputData[0];
        int[] nums  = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            nums [i] = list.get(i);
        }
        int k = (int) inputData[1];
        return solution.findMaxAverage(nums, k);
    }
}
